<template>
	
 	<div class="layui-layout layui-layout-admin" >
 	  <div class="adminnav1">	
        <Pagetop></Pagetop>
      </div>
      <div class="adminnav2">	
       	<Secondnav urlname="daili"></Secondnav>
      </div>
      
      <!-- 主体内容 -->
      <div class="layui-body kedou-admin" id="LAY_app_body app">
	    <div class="layadmin-tabsbody-item layui-show">
	    	<div class="pagelist">
	    		 <div class="layui-card-body">
		      		<fieldset class="layui-elem-field layui-field-title">
					  <legend v-if="commodityId">编辑代理</legend>
					  <legend v-else>新增代理</legend>
					</fieldset>
		      	</div>
		        <div class="layui-card-body">
		        	<div class="layui-form" lay-filter="">
		        		<div class="layui-form-item"><h3 style="font-weight:bold">基本信息</h3></div>
			        	<div class="layui-form-item">
							<label class="layui-form-label"><i style="color:#FF0000">*</i>选区域编号</label>
						    <div class="layui-input-inline">
								<select name="shopId" lay-filter="shopId">
									<option value="1" >+86中国</option>
									<option value="1" >+852中国香港</option>
									<option value="1" >+853中国澳门</option>
								</select>
							</div>
						</div> 
						<div class="layui-form-item">
							<label class="layui-form-label"><i style="color:#FF0000">*</i>代理手机号</label>
						    <div class="layui-input-block">
						        <input type="number" name="commodityName" placeholder="输入手机号码(限11位)"   v-model="itemData.name" autocomplete="off" class="layui-input a" maxlength="11">
						    </div>	
						</div> 
						<div class="layui-form-item">
							<label class="layui-form-label"><i style="color:#FF0000">*</i>代理商姓名</label>
						    <div class="layui-input-block">
						        <input type="text" name="commodityName" placeholder="输入代理商姓名（限10字）"   v-model="itemData.name" autocomplete="off" class="layui-input a" maxlength="10">
						    </div>	
						</div>
						<div class="layui-form-item">
							<label class="layui-form-label"><i style="color:#FF0000">*</i>登陆密码</label>
						    <div class="layui-input-block">
						        <input type="text" name="commodityName" placeholder="输入登陆密码(密码长度在6-20位)"   v-model="itemData.name" autocomplete="off" class="layui-input a" maxlength="20">
						    </div>	
						</div>
						<div class="layui-form-item"><h3 style="font-weight:bold">其它信息</h3></div>													   
						<div class="layui-form-item">
							<label class="layui-form-label"><i style="color:#FF0000">*</i>代理商等级</label>						
						    <div class="layui-input-inline">
								<select name="shopId" lay-filter="shopId" >
									<option value="0" >请选择代理商等级</option>
									<option value="1" >社长</option>
									<option value="2" >团长</option>
									<option value="3" >掌柜</option>
									<option value="4" >VIP</option>
								</select>
							</div>			
						</div>
					    <div class="layui-form-item">
							<label class="layui-form-label"><i style="color:#FF0000">*</i>邀请人设置</label>						
						    <div class="layui-input-inline">
								<select name="shopId" lay-filter="shopId">
									<option value="0" >请选择邀请人</option>									
								</select>
							</div>			
						</div>    
						<div class="layui-form-item">
							<label class="layui-form-label"><i style="color:#FF0000">*</i>上级代理商</label>
						     <div class="layui-input-inline">
								<select name="shopId" lay-filter="shopId">
									<option value="0" >请选择上级代理商</option>									
								</select>
							</div>	
						</div>	    
						<div class="layui-form-item">
							<label class="layui-form-label"><i style="color:#FF0000">*</i>产品组合</label>
						     <div class="layui-input-inline">
								<select name="shopId" lay-filter="shopId">
									<option value="0" >请选择产品组合</option>									
								</select>
							</div>	
						</div>			
						<div class="layui-form-item">
							<label class="layui-form-label"><i style="color:#FF0000">*</i>货款金额</label>
						    <div class="layui-input-block">
						        <input type="number" name="commodityName" placeholder="输入货款金额（限11位）"   v-model="itemData.name" autocomplete="off" class="layui-input a" maxlength="11">
						    </div>	
						</div>
						<div class="layui-form-item"><h3 style="font-weight:bold">打款信息</h3></div>	
						<div class="layui-form-item">
							<label class="layui-form-label">打款总账户</label>
						    <div class="layui-input-block">
						        <input type="number" name="commodityName" placeholder="输入打款总账户（限19位）"   v-model="itemData.name" autocomplete="off" class="layui-input a" maxlength="19">
						    </div>	
						</div>
						<div class="layui-form-item">
							<label class="layui-form-label">打款金额</label>
						    <div class="layui-input-block">
						        <input type="number" name="commodityName" placeholder="输入打款金额（限11位）"   v-model="itemData.name" autocomplete="off" class="layui-input a" maxlength="11">
						    </div>	
						</div>
						<div class="layui-form-item">
							<label class="layui-form-label">打款人账户</label>
						    <div class="layui-input-block">
						        <input type="number" name="commodityName" placeholder="输入打款人账户（限19位）"   v-model="itemData.name" autocomplete="off" class="layui-input a" maxlength="19">
						    </div>	
						</div>
						<div class="layui-form-item">
							<div class="layui-input-block">
								<button class="layui-btn layui-btn-normal" lay-submit lay-filter="setmyinfo" @click="confirmOk">确认</button>
							</div>
						</div>
					</div>	
		        </div>		      
	        </div>
	    </div>
	  </div>  
	     
	</div>
</template>
<script>
import Pagetop from '../../common/pagetop.vue'
import Secondnav from '../../common/secondnav.vue'
import Vue from 'vue' 
export default {	
  name: 'dladd',  
  components: {Pagetop,Secondnav},	  
  data () {
    return {   	
    	itemData:{logo:"",status:1,detailcontent:"",mallCommodityType:1,type:1},
    	shoplist:[],
    	grouplist:[],
    	fllist:[[],[],[],[]],
    	flcur:[],
    	gglist:[{name:"统一规格",amount:'',saleprice:'',goodsweight:'',extraprice:''}],
    	ruslist:[],
    	commodityId:'',
    	shopId:'',
    	flname:""
    }
  },
  mounted(){ 
  	var _this = this;
//  layui.use('upload', function(){
//		  var upload = layui.upload;
//		  var uploadInst = upload.render({
//		    elem: '#layuiadmin-upload-useradmin',//绑定元素
//		    data:{
//		    	type:2
//		    }
//		    ,url:'http://storage.g2ma.com/imgUpload/single' //上传接口
//		    ,done: function(res){
//		    	layer.msg('上传成功');
//		    	_this.itemData.logo=res.msg;
//		    }
//		    ,error: function(){
//		      layer.msg('上传失败');
//		    }
//		  });
//		  upload.render({
//		    elem: '#test2',
//		    data:{
//		    	type:2
//		    }
//		    ,url: 'http://storage.g2ma.com/imgUpload/multi'
//		    ,multiple: true
//		    ,before: function(obj){
//		      //预读本地文件示例，不支持ie8
//		      obj.preview(function(index, file, result){
//		        $('#demo2').append('<img width="100" height="100" src="'+ result +'" alt="'+ file.name +'" style="display:inline-block;margin-right:10px;">')
//		      });
//		    }
//		    ,done: function(res){
//		      layer.msg('上传成功');
//		      var img=_this.itemData.detailcontent;
//		      var imgs=img+'<img src="'+res.msg+'" />'
//		      _this.itemData.detailcontent=imgs;
//		    }
//		  });
//		  
//		});
//	this.getshop();
//	this.getfl(1,0);
//  window.dogg = this.dogg;
//	if(this.$route.query.commodityId){
//	  	this.commodityId=this.$route.query.commodityId;
//	  	this.shopId=this.$route.query.shopId;
//	  	this.getdate();
//	}	
  	
  },
  methods: {  
//		getdate:function(){
//			var _this = this; 	
//			var url="/huanxinsong/commodity/editJson"
//			var dates={
//		    	shopId:this.shopId,
//		    	commodityId:this.commodityId
//		    }
//			ajaxRequest(url,'GET','json',dates,function(ret,err){
//				_this.itemData=ret.content.commodityFullInfo;
//				_this.flname=ret.content.category.name
//				_this.getylgg();
//				_this.getgoodsxq();
//			})	
//			
//			
//		},
//		delimg:function(){
//			this.itemData.detailcontent="";
//			$('#demo2').html("");
//		},
//		getgoodsxq:function(){
//			var _this = this; 	
//			var url1="/commodity/getDetail"
//			var dates={
//		    	id:this.commodityId
//		    }
//			ajaxRequest(url1,'GET','json',dates,function(ret,err){
//				_this.itemData.detailcontent=ret.content.content
//				_this.itemData.detailId=ret.content.id
//				$('#demo2').html(ret.content.content)
//			})	
//		},
//		
//		getylgg:function(){
//			var _this = this; 	
//			var url="/huanxinsong/commodity/getinventorygoodsparams"
//			var dates={
//		    	commodityId:this.commodityId,
//		    	shopId:this.shopId
//		    	
//		    }
//			ajaxRequest(url,'GET','json',dates,function(ret,err){
//				var arr=ret;
//				var goodsId="";
//				for(var i=0;i<arr.length;i++){
//					var cname=arr[i].specSerial;
//					if(cname.indexOf(";")>=0){
//						var yname=cname.split(";");
//					}
//					else{
//						if(cname!="统一规格"){
//							var yname=[];
//							yname[0]=cname;
//						}
//						else{
//							var yname=cname;
//						}
//					}
//					arr[i].yyname=yname;
//					goodsId=goodsId+arr[i].id+","
//					if(yname.toString().indexOf(":")<0){
//						var str=cname;
//					}
//					else{
//						var str="";
//						for(var j=0;j<yname.length;j++){
//							str=str+yname[j].split(":")[1]+","
//							
//						}
//					}
//					arr[i].name=str;
//					arr[i].saleprice=arr[i].price;
//					arr[i].goodsweight=arr[i].weight;
//					
//				}
//				_this.itemData.goodsId=goodsId.substr(0,goodsId.length-1);
//				_this.gglist=arr;
//			})	
//		},
//		getshop:function(){
//			var _this = this; 										      	
//		    var url='/commodity/getShopsByDealerId'
//		    var dates={
//		    	dealerId:localStorage.getItem("id")
//		    }
//			ajaxRequest(url,'GET','json',dates,function(ret,err){
//				_this.shoplist=ret.content;
//				if(_this.shopId){
//					_this.itemData.shopId=_this.shopId
//				}
//				else{
//					_this.itemData.shopId=ret.content[0].id;
//				}
//				_this.getfz();
//			})				
//			
//		},		
//		getfz:function(){
//			var _this=this;
//	  		var dates={
//	  			dealerId:localStorage.getItem("id"),			
//	  			shopId:_this.itemData.shopId
//	  		}
//				var url="/commodity/getShopGroups";		
//	  		ajaxRequest(url,'GET','json',dates,function(ret,err){ 
//	  		 	_this.grouplist=ret.content;
//	  		 	if(_this.commodityId){
//	  		 		//_this.itemData.groupId=
//	  		 	}
//	  		 	else{
//	  		 		_this.itemData.groupId=ret.content[0].id;
//	  		 	}
//	  		})
//		},
//	getfl:function(pid,index){//分类
//		if(pid!=1){
//			this.itemData.categoryId=pid;
//			this.flcur[index-1]=pid;
//		}
//		var _this=this;
//		var data={
//			parentId:pid,			
//		}
//		var url = "/category/getSubCategories";
//		ajaxRequest(url,'GET','json',data,function(ret,err){ 
//			 for(var i=index;i<4;i++){
//			 	var arr=[];
//			 	Vue.set(_this.fllist,i,arr);
//			 }
//		   Vue.set(_this.fllist,index,ret.content)
//		})
//	},
//	getgg:function(){//规格
//		var _this=this;
//		if(this.itemData.categoryId){
//	  		var _this = this;
//			var id=this.itemData.categoryId;
//			layer.open({
//	            type: 2
//	            ,title: '选择规格值'
//	            ,shadeClose: false//点击遮罩关闭
//	            ,content:baseurl+'/gglist'
//	            ,area:['90%', '80%']          
//	            ,success : function(layero, index){
//			        var iframeWin = window[layero.find('iframe')[0]['name']];
//			        iframeWin.getdates(id);
//		        },	      
//	        });
//	  	}
//	  	else{
//	  		layer.msg('请先选择分类');
//	  	}
//	}, 
//	delgg:function(){
//		this.gglist=[{name:"统一规格",amount:'',saleprice:'',originalprice:'',goodsweight:''}]	
//	},
//	dogg:function(arr){
//		var carr=[];
//		for(var i=0;i<arr.length;i++){
//			var obj={
//	  			name:'',
//	  			yyname:'',
//	  			amount:'',
//				saleprice:'',
//				originalprice:'',
//				goodsweight:'',
//				
//	  		}
//			obj.yyname=arr[i];
//			var str="";
//			
//			for(var j=0;j<arr[i].length;j++){
//				
//				str=str+arr[i][j].split(":")[1]+":"
//			}
//			obj.name=str;
//			carr.push(obj);
//		}
//		this.gglist=carr;
//	},
	confirmOk:function(){
		alert('开发中')
		return false;
		var _this = this;   	
		var len = $(".a").length;
		for(var i = 0; i < len; i++) {
			if($(".a").eq(i).val() == ''||$(".a").eq(i).val()<=0) {
				var msg = $(".a").eq(i).attr("placeholder");
				layer.msg('请输入正确的'+msg);
				return;
			}
		}	
		if(!this.itemData.categoryId){
			layer.msg('请选择分类');
			return false;
		}
		/*if(!this.itemData.logo){
			layer.msg('请上传商品图片');
			return false;
		}
		if(!this.itemData.detailcontent){
			layer.msg('请上传商品详情图片');
			return false;
		}*/
		
		var dates=this.itemData;
		if(this.gglist.length==1){
			dates.baseamount=this.gglist[0].amount;
			dates.basesaleprice=this.gglist[0].saleprice;
			dates.weight=this.gglist[0].goodsweight;
			dates.baseextraprice=this.gglist[0].extraprice;
			dates.amount=[];
			dates.saleprice=[];
			dates.specSerial=[];
			dates.goodsweight=[];
			dates.extraprice=[];
		}
		else{
			var arr=this.gglist;
			var specSerial="";
			var amount="";
			var saleprice="";
			var goodsweight="";
			var extraprice="";
			var originalprice=[];
			for(var i=0;i<arr.length;i++){
				specSerial=specSerial+arr[i].yyname.join(";")+',';
				amount=amount+arr[i].amount+',';
				saleprice=saleprice+arr[i].saleprice+',';
				goodsweight=goodsweight+arr[i].goodsweight+',';
				extraprice=extraprice+arr[i].extraprice+',';
				originalprice[i]=0
			}
			specSerial=specSerial.substr(0,specSerial.length - 1);
			amount=amount.substr(0,amount.length - 1);
			saleprice=saleprice.substr(0,saleprice.length - 1);
			goodsweight=goodsweight.substr(0,goodsweight.length - 1);
			extraprice=extraprice.substr(0,extraprice.length - 1);
			dates.specSerial=specSerial;
			dates.amount=amount;
			dates.saleprice=saleprice;
			dates.goodsweight=goodsweight;
			dates.extraprice=extraprice;
			dates.basesaleprice=0;
			dates.originalprice=originalprice;
			dates.weight=0;
		}
		dates.startTime="";
		dates.endTime="";
		dates.logobatch="";
		dates.shopCommodityGroupName="";
		var url = "/huanxinsong/commodity/publishgernalgoods";
	  	ajaxRequest(url,'GET', 'json',dates, function(ret, err){
			layer.msg("操作成功");
			setTimeout(function(){
				_this.$router.push({path:'/jfshoplist'})
	      	},1000)
		})
	}
  },
  updated:function(){
  	var _this = this;
	layui.use('form', function(){
	  var form = layui.form;
	  form.render();
	  form.on("select(groupId)", function(data){										
		   _this.itemData.groupId = data.value
	  });
	  form.on("select(shopId)", function(data){										
		   _this.itemData.shopId = data.value
	  });
	  form.on("select(status)", function(data){										
		   _this.itemData.status = data.value
	  });
	});
		
  },
}
</script>
<style>
	#J_imageView img{width:400px;display:block;}
	.fllist ul{display:inline-block; width: 20%;height:250px;margin-right:1%;overflow:hidden;overflow-y:scroll;border:1px solid #eee;}
	.fllist ul li{height:30px;line-height:30px;padding:5px 20px;border-bottom:1px solid #eee;cursor:pointer;}
	.fllist ul li.cur{ background-color:#3276df;color:#fff;}
	#demo2 img{display:inline-block;margin-right:10px;width:100px;height:100px;}
</style>
